<?php

declare(strict_types=1);

namespace App\Admin\Controller;

use App\Admin\Annotation\Auth;
use App\Admin\Service\System\SystemUserService;
use App\Admin\Service\System\UserAuthService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\GetMapping;
use Newbie\Annotation\Attributes\Route\PostMapping;
use Newbie\Helper\LoginUser;
use support\Response;

/**
 * 首页方法控制器
 * Class CommonController
 * @package App\system\Controller
 */
class IndexController extends BaseController {

    #[Inject]
    protected SystemUserService $systemUserService;

    #[Inject]
    protected UserAuthService $userService;


    /**
     * 用户信息
     * @return Response
     */
    #[GetMapping("/userInfo"), Auth]
    public function getInfo (): Response {
        return $this->success($this->systemUserService->getInfo());
    }

    /**
     * 刷新token
     * @param LoginUser $user
     * @return Response
     */
    #[PostMapping("/refresh"), Auth]
    public function refresh (LoginUser $user): Response {
        return $this->success(['token' => $user->refresh()]);
    }
}